package com.yuw.singleton;

import java.util.Objects;

public class Student {
    // 成员变量
    private String stuName;
    private String stuSex;
    private int stuAge;
    // 显式写出默认的构造方法
    public Student(){
    }

    public Student(String stuName, String stuSex, int stuAge) {
        this.stuName = stuName;
        this.stuSex = stuSex;
        this.stuAge = stuAge;
    }

    // 行为方法
    public  void  doStuding(){
        System.out.println("I am studing...");
    }

    public  boolean equals(Object stu){
        // == 判定成立，则内容一定相同
        if (this == stu) {
            return true;
        }
        // 判定内容是否相等
        if (stu instanceof Student) {
            // 强制类型转换
            Student student = (Student) stu;
            // 按业务逻辑进行内容的相等判定
            // 规定：只有姓名、年龄、性别同时相同才相等
            if (this.stuName != null && this.stuName.equals(student.stuName)
                    &&
                this.stuSex != null && this.stuSex.equals(student.stuSex)
                    &&
                    this.stuAge == student.stuAge){
                return  true;

            }
        }
        //判定结果不相等
        return false;
    }
    /*@Override
    public boolean equals(Object o) {
        // == 判定成立，则内容一定相同
        if (this == o) return true;
        // 比较的对象如果为null，或者二者不是同一类型，则返回false
        if (o == null || getClass() != o.getClass()) return false;
        // 按业务逻辑进行内容的相等判定
        Student student = (Student) o;
        return stuAge == student.stuAge &&
                (stuName != null && stuName.equals( student.stuName)) &&
                Objects.equals(stuSex, student.stuSex);
    }*/

    @Override
    public int hashCode() {

        return Objects.hash(stuName, stuSex, stuAge);
    }


    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public String getStuSex() {
        return stuSex;
    }

    public void setStuSex(String stuSex) {
        this.stuSex = stuSex;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }
}
